package com.ruoyi.platform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.platform.domain.Advertisers;
import com.ruoyi.platform.service.IAdvertisersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作广告商Controller
 * 
 * @author ruoyi
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/platform/advertisers")
public class AdvertisersController extends BaseController
{
    @Autowired
    private IAdvertisersService advertisersService;

    /**
     * 查询合作广告商列表
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Advertisers advertisers)
    {
        startPage();
        List<Advertisers> list = advertisersService.selectAdvertisersList(advertisers);
        return getDataTable(list);
    }

    /**
     * 导出合作广告商列表
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:export')")
    @Log(title = "合作广告商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advertisers advertisers)
    {
        List<Advertisers> list = advertisersService.selectAdvertisersList(advertisers);
        ExcelUtil<Advertisers> util = new ExcelUtil<Advertisers>(Advertisers.class);
        util.exportExcel(response, list, "合作广告商数据");
    }

    /**
     * 获取合作广告商详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:query')")
    @GetMapping(value = "/{advertiserId}")
    public AjaxResult getInfo(@PathVariable("advertiserId") String advertiserId)
    {
        return success(advertisersService.selectAdvertisersByAdvertiserId(advertiserId));
    }

    /**
     * 新增合作广告商
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:add')")
    @Log(title = "合作广告商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advertisers advertisers)
    {
        return toAjax(advertisersService.insertAdvertisers(advertisers));
    }

    /**
     * 修改合作广告商
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:edit')")
    @Log(title = "合作广告商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advertisers advertisers)
    {
        return toAjax(advertisersService.updateAdvertisers(advertisers));
    }

    /**
     * 删除合作广告商
     */
    @PreAuthorize("@ss.hasPermi('platform:advertisers:remove')")
    @Log(title = "合作广告商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertiserIds}")
    public AjaxResult remove(@PathVariable String[] advertiserIds)
    {
        return toAjax(advertisersService.deleteAdvertisersByAdvertiserIds(advertiserIds));
    }
}
